package com.hou.mqacting.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * 配置优先级队列
 */
@Configuration
public class MessageConfig02 {

    //创建交换器绑定两个有优先级的队列
    @Bean
    public DirectExchange prechange(){
        return new DirectExchange("prechange",true,false);
    }
    @Bean
    //优先级为10的队列
    public Queue preQueue1(){
        Map<String, Object> args = new HashMap<>();
        args.put("x-max-priority", 10); //优先级
        return new Queue("preQueue1",true,false,false,args);
    }
    @Bean
    Binding bindingPre1Messages() {
        return BindingBuilder.bind(preQueue1()).to(prechange()).with("pre1Key");
    }

    //优先级为20的队列
    @Bean
    public Queue preQueue2(){
        Map<String, Object> args = new HashMap<>();
        args.put("x-max-priority", 20); //优先级
        return new Queue("preQueue2",true,false,false,args);
    }
    @Bean
    Binding bindingPriMessages() {
        return BindingBuilder.bind(preQueue2()).to(prechange()).with("pre2Key");
    }

}
